<?php
namespace addons\csminvite\library;
use think\Config;
use think\Request;
use think\Response;
use think\Url;
use think\View as ViewTemplate;
use think\exception\HttpResponseException;
/**
 */
class CsminviteNotifyType
{

    /**
     * Copy from traits\controller\Jump.php#error function
     */
    protected function _error($msg = '', $url = null, $data = '', $wait = 3, array $header = [])
    {
        CsminviteNotifyType::error($msg,$url,$data,$wait,$header);
    }
    
    
    public static function error($msg = '', $url = null, $data = '', $wait = 3, array $header = []){
        
        if (is_null($url)) {
            $url = Request::instance()->isAjax() ? '' : 'javascript:history.back(-1);';
        } elseif ('' !== $url && !strpos($url, '://') && 0 !== strpos($url, '/')) {
            $url = Url::build($url);
        }
        
        $type = Request::instance()->isAjax()
        ? Config::get('default_ajax_return')
        : Config::get('default_return_type');
        
        $result = [
            'code' => 0,
            'msg'  => $msg,
            'data' => $data,
            'url'  => $url,
            'wait' => $wait,
        ];
        
        
        if ('html' == strtolower($type)) {
            $template = Config::get('template');
            $view = Config::get('view_replace_str');
            
            $result = ViewTemplate::instance($template, $view)
            ->fetch(Config::get('dispatch_error_tmpl'), $result);
        }
        
        $response = Response::create($result, $type)->header($header);
        
        throw new HttpResponseException($response);
    }

 
 
}